<?php 
/**
 * 
 * 用户信息 处理类
 * @author tanzhe
 *
 */
class userinfo {
	private $userinfoModel;
	private $url;
	
	public function __construct() {
		$this->userinfoModel = new UserinfoModel();
		$this->url = new Url();
		/*
		global $trust_server;
		if (!array_key_exists($_SERVER['REMOTE_ADDR'], $trust_server)) {
			echo "fail:auth ".$_SERVER['REMOTE_ADDR'];
			exit;
		}
		*/
	}
	
	public function get() { //获取用户信息
		$key = $this->url->get('key');
		$ret= $this->userinfoModel->get($key);
		$callback = $this->url->get('jsonpcallback');
		Json::do_jsonp_encode($callback, $ret);
	}
	
	public function show() { //查看用户信息 测试用
		$key = $this->url->get('key');
		$ret = $this->userinfoModel->show($key);
	}
	
	public function fillEnergy() { //恢复体力
		$url = new Url();
	  	$key = $url->get('key');
		$ret = $this->userinfoModel->fillEnergy($key);
		
		$callback = $url->get('jsonpcallback');
		Json::do_jsonp_encode($callback,$ret);
	}
	
	public function fillEnergyByCash() { //通过cash直接恢复体力
		$url = new Url();
	  	$key = $url->get('key');
		$ret = $this->userinfoModel->fillEnergyByCash($key);
		
		$callback = $url->get('jsonpcallback');
		Json::do_jsonp_encode($callback,$ret);
	}
	
	public function setNickname() { //设置昵称
		$url = new Url();
	  	$key = $url->get('key');
	  	$nickname = $url->get('nickname');
		$ret = $this->userinfoModel->setNickname($key, $nickname);
		
		$callback = $url->get('jsonpcallback');
		Json::do_jsonp_encode($callback,$ret);
	}
}
?>